package com.pacy.pacybaseproject.base;

import androidx.databinding.ViewDataBinding;

import com.gyf.immersionbar.ImmersionBar;
import com.pacy.pacybaseproject.MainActivity;
import com.pacy.pacybaseproject.R;
import com.pacy.pacybaseproject.activitys.AllReceiveActivity;
import com.pacy.pacybaseproject.activitys.CyclingActivity;
import com.pacy.pacybaseproject.activitys.ExSuccessActivity;
import com.pacy.pacybaseproject.activitys.ExchangeDetailActivity;
import com.pacy.pacybaseproject.activitys.RoutingActivity;
import com.pacy.pacybaseproject.activitys.RoutingSearchActivity;
import com.pacy.pacybaseproject.activitys.TravelActivity;

import me.goldze.mvvmhabit.base.BaseActivity;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.views.BaseToolbar;
import me.goldze.mvvmhabit.views.StateLayout;

/**
 * @author PACY
 * @date 2021/11/23
 * description:
 */
public abstract class BaseXActivity<V extends ViewDataBinding, VM extends BaseViewModel> extends BaseActivity<V, VM> {
    private StateLayout stateLayout;
    private BaseToolbar toolbar;

    public void setStateLayout(StateLayout stateLayout) {
        this.stateLayout = stateLayout;
    }

    public void setToolbar(BaseToolbar toolbar) {
        this.toolbar = toolbar;
        toolbar.setBackClick(() -> {
            finish();
        });
    }

    @Override
    public void initData() {
        super.initData();
        if (this instanceof MainActivity||this instanceof TravelActivity
                || this instanceof RoutingActivity || this instanceof RoutingSearchActivity
                || this instanceof ExchangeDetailActivity || this instanceof ExSuccessActivity
    || this instanceof CyclingActivity) {
            ImmersionBar.with(this).statusBarDarkFont(false).init();
        } else {
            ImmersionBar.with(this).fitsSystemWindows(true).statusBarColor(R.color.white100).statusBarDarkFont(true).init();
        }

    }

    @Override
    public void showLoading() {
        super.showLoading();
        if (stateLayout != null) {
            stateLayout.showLoading();
        }
    }

    @Override
    public void showContent() {
        super.showContent();
        if (stateLayout != null) {
            stateLayout.showContent();
        }
    }

    @Override
    public void showError() {
        super.showContent();
        if (stateLayout != null) {
            stateLayout.showError();
        }
    }

    @Override
    public void showEmpty() {
        super.showEmpty();
        if (stateLayout != null) {
            stateLayout.showEmptyContent();
        }
    }
}
